我想做这样的查询:
$this->set('title', 'Lista de Posts');
$Posts = $this->Post->query("SELECT id,Titulo,Data,Hora,RIGHT(Conteudo,200) AS Conteudo,Usuario FROM posts;");
$this->set('posts', $Posts);
$this->layout = 'home';
但在 View 中我收到此消息:
通知(8):未定义索引:Post [APP/View/Posts/home.ctp,第 4 行]
但是使用 $Posts = $this->Post->find('all') 就可以了。
请问谁能帮我在 cake php 中使用 RIGHT(Conteudo,200) 吗?
谢谢
最佳答案
如果您是 Cake 新手,请忘记“查询”方法。这是针对非常特殊的情况。
在您的 PostsController 中:
class PostsController extends AppController {
var $helpers = array('Text');
public function index() {
$posts = $this->paginate();
$this->set('posts', $posts);
}
}
您认为:
foreach($posts as $post) {
echo $this->Text->tail($post['Post']['conteudo'], 200);
}
关于php - cakephp 中的 mysql 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18257686/