2017-02-19 22 views
0

像URL如何在CodeIgniter中發送id值?

Index.php/constructor/method/1 

我想ID。 我用

anchor("constructor/method/{$article->id}",'Edit'); 

這是不行的,我得到以下錯誤:

使用非對象爲對象

我怎麼能檢索的id值?

+0

生成的錨是什麼樣的? – ourmandave

+0

您應該嘗試在問題中包含更多的細節。 –

回答

1

如果你的「身份證」是URI:index.php文件/構造函數/方法/ 1

您可以通過使用URI庫和段獲得的價值。

即。

URI:的index.php /構造/方法/ 1

$ ID = $這個 - > URI->段(3);

請隨時在文檔中檢查this page上URI區段操作的其他功能。

0

我不確定你從哪裏得到$article->id,因爲你沒有粘貼足夠的代碼。

試穿控制器

$data['example'] = anchor("controller/method/" . $article->id,'Edit'); 
$this->load->view('example_view', $data); 

然後在視圖

<?php echo $example_link;?> 

您可能需要設置航線

的config/routes.php文件https://www.codeigniter.com/user_guide/general/routing.html#examples

$route['controller/method/(:any)'] = 'controller/method/$1'; 

的conf ig/autoload.php

$autoload['helper'] = array('url'); 
相關問題