0

单击按钮后,我想从控制器调用一个函数以将一些数据存储在数据库中。即,在 javascript (jquery) 中,我有:

$( '.opener' ).click(function() {
        FB.ui({
            method: 'feed',
                // redirect_uri: '/index.php',
            link: 'http://test.com',
            name: 'Bleh',
            caption: 'Blah',
            description: 'Testing!'
            // {{$artist->stage_name}} 
            });

        // Want to call controller function here:
         {{Artists:function}}


      });

在这种情况下,如何从控制器调用该函数?在上述情况下,控制器将是 ArtistsController,而函数是“function”。谢谢你。

4

4 回答 4

0

您只需像普通 URL 一样链接到它 - 如下所示:

$( '.opener' ).click(function() {
        FB.ui({
            method: 'feed',
            link: 'http://test.com/artists/function', // put the link here
            name: 'Bleh',
            caption: 'Blah',
            description: 'Testing!'
            });
      });

在你的 routes.php 中

Route::get('/artists/function', array('uses' => 'ArtistsController@function'));
于 2013-07-17T03:54:24.060 回答
0

将您的路线更改为

Route::get('artists/function', array('as' => 'artists/function', 'uses' => 'ArtistsController@function'));
于 2013-07-26T15:42:49.040 回答
0

例如,您可以使用声明为 DB 类的函数,Controller但您可以直接在没有路由的情况下执行此操作:

<html>
 <body>
  <h1>home.blade.php</h1>
  <?php 
   function test(){ 
    $users = DB::table('users')->join('users_views', 'users.id', '=', 'users_views.id')->where('users_views.id',Auth::user()->id)-‌​&gt;get(); foreach ($users as $permiso) { $ck2 = $permiso->perm; } 
   } 
   test(); 
   echo ";)"; 
  ?>
 </body>
</html>
于 2017-01-05T06:13:39.517 回答
0
<?php   
    function get_fotos_productos($id_prod){
        //here call DB Class 
        foreach ($fotos as $foto)
        {
            $foto='<img src="img/productos/big/'.$foto->foto.'" width="50" alt="">';
            echo  $foto;
        } 

 } ?>

例如在我看来

<ul class="nav navbar-nav navbar-right">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="glyphicon glyphicon-shopping-cart"></span> 7 - Items<span class="caret"></span>
        </a>
        <ul class="dropdown-menu dropdown-cart" role="menu">

        <?php 
        $id_prod=3;
        foreach ($cart as $key => $value) {

            echo '                          
            <li>
                <span class="item">
                    <span class="item-left">
                        '. get_fotos_productos($id_prod).'        
                        <span class="item-info">
                            <span>Codigo :'.$value["code"].'</span>
                            <span>Cantidad : '.$value["qty"].'</span>            
                        </span>
                    </span>
                    <span class="item-right">
                        <button class="btn btn-xs btn-danger pull-right">x</button>
                    </span>
                </span>
            </li>
            ';        

         }
         ?>
         <li class="divider">
         <li><?php echo "Costo Total:".$total; ?></li>
         <li><a class="text-center" href="">View Cart</a></li>
      </ul>

    <!-- end snippet -->
于 2017-01-05T06:52:28.083 回答