2014-10-05 56 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]'); 

現在你可以寫你的代碼,這個方法,它會工作。