如何在Laravel4中单击按钮后调用jquery中的控制器函数

如何在Laravel4中单击按钮后调用jquery中的控制器函数,jquery,controller,laravel,laravel-4,Jquery,Controller,Laravel,Laravel 4,我想从控制器调用一个函数,在单击按钮后将一些数据存储在数据库中。也就是说,在javascript(jquery)中,我有: 在这种情况下,如何从控制器调用函数?在上述情况下,控制器将是ArtistsController,函数“function”。多谢各位 您只需像普通URL一样链接到它-类似以下内容: $( '.opener' ).click(function() { FB.ui({ method: 'feed', link: 'h

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


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

您只需像普通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'));
把你的路线改成

Route::get('artists/function', array('as' => 'artists/function', 'uses' => 'ArtistsController@function'));

您可以使用一个函数,例如将DB类声明为
控制器
,但您可以直接执行该函数,而无需路由:

<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)-‌​>get(); foreach ($users as $permiso) { $ck2 = $permiso->perm; } 
   } 
   test(); 
   echo ";)"; 
  ?>
 </body>
</html>

home.blade.php
这会调用美工控制器中的函数“function”吗?home.blade.php$fotos=DB::table('productos')->where('id','=','id_prod)->get();
<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)-‌​>get(); foreach ($users as $permiso) { $ck2 = $permiso->perm; } 
   } 
   test(); 
   echo ";)"; 
  ?>
 </body>
</html>
<?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 -->