2014-10-05 106 views
0

我最近2年开发codeigniter应用程序,自从我从codeigniter本身开始我的mvc模式样式以来,现在我不是一个沉重的命令行用户,所以起初我有一些Codeigniter的学习曲线,但我穿过它,并开始使用代码点火器开发应用程序,因为我们不需要配置很多,一切都在一个zip文件中,但现在不幸的是,codeigniter已经死了,我只是一个人在我的团队中,我不得不依靠其他由其他人信任的第三方工具,所以我决定切换到laravel,现在在启动它时,由于作曲者和其他所有东西而从代码转换器中迁移方式非常艰难,但我也以某种方式越过了这些工具,但我现在与路由混淆了和其他的东西,我已经尝试了很多教程,但我仍然无法看到如何从应用程序中迁移,我在哪里管理学生,他们可以在哪里更改电子邮件,c hange电话号码更新的东西,在codeigniter这很容易,但我不怎么处理laravel路由这个问题,现在这个问题听起来愚蠢的社区谁已经在laravel工作,但如果你从我的角度来看它会影响我的面包和黄油。这就是我笨Laravel中的控制器方法

class Student extends CI_Controller{ 
    // usual piece of code of constructor 
    function update_email() 
    { 
      // piece of code to update email 
    } 
} 

使用的方法,但是现在laravel路由系统和所有我不知道如何处理这个资源控制器看起来像这样

<?php 

class StudentController extends \BaseController { 

    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    */ 
    public function index() 
    { 

    } 


    /** 
    * Show the form for creating a new resource. 
    * 
    * @return Response 
    */ 
    public function create() 
    { 
     // 
    } 


    /** 
    * Store a newly created resource in storage. 
    * 
    * @return Response 
    */ 
    public function store() 
    { 
     // 
    } 


    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function show($id) 
    { 
     // 
    } 


    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function edit($id) 
    { 
     // 
    } 


    /** 
    * Update the specified resource in storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function update($id) 
    { 
     // 
    } 


    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 


} 

现在每一个部分是好吧,但我怎么可以接近我只更新电子邮件地址或只有电话号码和东西的东西

回答

0

其实,在你的问题,你有一个RESTful控制器可能在这个时候,因为你是新来Laravel和使用CI被迷惑你,所以可能是你很这么多的不航线自动化URL映射中使用。在这种情况下,为了方便起见,我建议您使用普通控制器,这与您在CI中所做的几乎完全相同,但在此处Laravel中,您必须为每个操作声明route。所以,只需要创建两条路线这样的:

Rouite::get('something/edit/{id}', array('uses' => '[email protected]', 'as' => 'edit.record')); 

Rouite::post('something/update/{id}', array('uses' => '[email protected]', 'as' => 'update.record')); 

然后创建一个类/控制器,并声明这些方法:

class StudentController extends baseController { 

    // URL: http://example.com/something/edit/10 and it'll listen to GET request 
    public function edit($id) { 
     // $record = Load the record from database using the $id/10 
     // retuen View::make('editform')->with('record', $record); 
    } 

    // URL: http://example.com/something/update/10 and it'll listen to POST request 
    public function update($id) { 
     // Update the record using the $id/10 
    } 
} 

在你的表格,你需要使用http://example.com/something/update/10action,你可以使用route('update.record')或者url('something/update/10')来生成表格中的action。阅读更多关于Laravel Documentation

0

你在这里创建的(或者可能是生成的)被称为Restful controller。这是管理CRUD操作的一种“标准方式”(创建/读取/更新/删除)。但是没有必要这样做。你可以在你的控制器中添加你想要的任何方法,而不是使用Restful控制器。这是你的选择。

你可以在你的函数新方法

function updateEmail() 
{ 
    // do here whatever you want 
} 

,并在您routes.php文件中添加新的路由创建:

Route::match(array('GET', 'POST'), '/changegemail', '[email protected]'); 

现在你可以写你的代码,这个方法,它会工作。