【问题标题】:Template fail for non-exist php error模板因不存在的 php 错误而失败
【发布时间】:2013-07-26 07:49:34
【问题描述】:

我正在与 Propel 和 Smarty 合作。我有一个servicios.php 文件,它只包含:

include('private/autoload.php');

// Servicios Todos
$servicios = ServicioQuery::Create()->orderByTitulo(Criteria::ASC)->find()->toArray();
$smarty->assign('servicios',$servicios);

// Servicio a mostrar
$servQry = ServicioQuery::Create();
if($url->getParam(3) == '') {
    $servicio = $servQry->findOneByIdservicio(1);
}else{
    $servicio = $servQry->findOneBySlug($url->getParam(3));
}

// Error Line ?
$servicio = $servicio->toArray();


$smarty->assign('servicio',$servicio);

$smarty->display('templates/servicio.tpl');

文件servicio.tpl 包含:

<html>
<head>
    {include file="html_head.tpl"}
</head>
<body>
....
<h2>{$servicio.Titulo}</h2>
<div class="span3">
     <img class="borderFoto" src="assets/img/servicios/{$servicio.Slug}.jpg" alt="{$servicio.Slug}.jpg" />
</div>
<div class="span7">
     {$servicio.Descripcion}
</div>
</body>
</html>

html_head.tpl

<title>Pilar Medicina Est&eacute;tica</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/style.css">

所以,问题是,Css 样式不加载。使用 Firebug 显示,不是打印 Css 代码,而是打印:

致命错误:在 a 上调​​用成员函数 toArray() 非对象在 /media/Datos/www/PilarMedicinaEstetica/owner/servicios.php15 行

但是,错误很少见,因为数据显示正确,$serviciovar_dump 不标记错误:

array(7) { ["Idservicio"]=> int(1) ["Idsitio"]=> int(1) ["Titulo"]=> 字符串(15)“服务演示 1”[“描述”]=> 字符串(979)“Nulla commodo commodo iaculis...eget pellentesque nunc nisi ac sem。” ["Slug"]=> 字符串(17) "servicio_demo_uno" ["Shares"]=> int(1) ["Activo"]=> bool(true) }

在 index.php 中,执行相同的步骤,然后工作。为什么这里没有?有任何想法吗 ?。

【问题讨论】:

  • Call to a member function toArray() on a non-object你的对象不是对象而是数组?
  • @Bondye $servicio 是“Servicio”类的对象。如果我尝试传递对象,Smarty 会说:致命错误:无法使用 Servicio 类型的对象作为数组...
  • Uhmm 而不是使用{$servicio.Titulo} 不能传递对象而不是创建数组。像这样{$servicio-&gt;Titulo}?否则尝试在$servicio-&gt;toArray() 之前和之后print_r($servicio) 并进行比较。

标签: php smarty propel


【解决方案1】:

错误是我传递了一个错误的 slug,查询返回一个空集合 jiji。

【讨论】:

    猜你喜欢
    • 2015-05-10
    • 2013-03-14
    • 2014-01-06
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2012-08-09
    • 2023-03-17
    相关资源
    最近更新 更多