Error

Call to a member function getCategoryTitle() on null

/home/c/cl43698/public_html/protected/components/SeoBuilder.php(34)

22         return self::$instance;
23     }
24 
25     public function makeTextFromTemplate($model, $template)
26     {
27         if (!$template) {
28             return null;
29         }
30         $text = preg_replace_callback('~(\{[a-z]+\})~ui', function ($matches) use ($model) {
31             $match = str_replace(['{', '}'], '', $matches[0]);
32             try {
33                 if ($match == 'category') {
34                     return $model->getCategoryTitle();
35                 }
36                 return $model->$match ?? null;
37             } catch (\Exception $ex) {
38                 return 'undefined';
39             }
40         }, $template);
41         return $text;
42     }
43 }

Stack Trace

#1
+
 /home/c/cl43698/public_html/protected/components/SeoBuilder.php(40): preg_replace_callback("~(\{[a-z]+\})~ui", Closure, "Купить {title} {category}")
35                 }
36                 return $model->$match ?? null;
37             } catch (\Exception $ex) {
38                 return 'undefined';
39             }
40         }, $template);
41         return $text;
42     }
43 }
#2
+
 /home/c/cl43698/public_html/protected/controllers/ShopController.php(113): SeoBuilder->makeTextFromTemplate(null, "Купить {title} {category}")
108     public function actionProduct($id)
109     {
110         $product = Product::model()->visibled()->findByPk($id);
111         $this->prepareSeo($product->meta_title ?: $product->title);
112         if(!$product->meta_title) {
113             $product->meta_title = \SeoBuilder::maker()->makeTextFromTemplate($product, D::cms('shop_product_title')) ?? null;
114         }
115         if(!$product->meta_desc) {
116             $product->meta_desc = \SeoBuilder::maker()->makeTextFromTemplate($product, D::cms('shop_product_desc')) ?? null;
117         }
118         if(!$product->meta_key) {
#15
+
 /home/c/cl43698/public_html/index.php(53): CApplication->run()
48 
49 $config = dirname(__FILE__) . '/protected/config/main.php';
50 
51 require_once($yii);
52 
53 Yii::createWebApplication($config)->run();
54 
55 ob_end_flush();
2024-03-29 03:37:27 Apache/2.4.29 Yii Framework/1.1.17