English 中文(简体)
公开标语
原标题:Opencart meta title include store name
  • 时间:2012-04-10 10:22:06
  •  标签:
  • php
  • opencart

如何在文件类别中找到储存名称。 这是我努力做到的:

public function setTitle($title) {

    // Append store name if small title
    if(strlen($title) < 30){
        $this->title = $title .   -   . $this->config->get("store_name");
    } else {
        $this->title = $title;
    }
}

Although the $this is referring to the document class. How to I get the config?

采用开放式1.5.2.1的最新版本

当检查<代码>index.php文档时,看汇装如何

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set( load , $loader);

// Config
$config = new Config();
$registry->set( config , $config);
最佳回答

开放艺术利用某种依赖注射从图书馆课堂进入登记处。 这种技术适用于许多图书馆课堂,如客户、附属公司、货币、税、权重、长度和车类。 简言之,文件类别是没有通过登记处标的少数类别之一。

如果你愿意遵守这项公约,我建议你修改索引.php和图书馆/文件。 php 以便文件构造者将登记处作为论点:

class Document {

        [...]

        // Add the constructor below
        public function __construct($registry) {
                $this->config = $registry->get( config );
        }

        [...]

        public setTitle($title) {
            if(strlen($title) < 30){
                $this->title = $title .   -   . $this->config->get("store_name");
            } else {
                $this->title = $title;
            }
        }

}

现在,你只需要将登记册的标注列入索引.php。

// Registry
$registry = new Registry();

[...]

// Document
$registry->set( document , new Document($registry));
问题回答

您不能在文件类别中使用$->cofig,因为它没有config 财产,也没有像控制器类那样的魔法

你可以试图改变你的头脑控制器。

public function index() {

   $title = $this->document->getTitle();
   if(strlen($title) < 30){
      $this->data[ title ] = $title .   -   . $this->config->get("store_name");
   } else {
      $this->data[ title ] = $title;
   }

   // ....
}

页: 1 页: 1

如果你想要在文件类别中使用美元,你可以使用全球变量:

public function setTitle($title) {

    global $config;
    // Append store name if small title
    if(strlen($title) < 30){
        $this->title = $title .   -   . $config->get("store_name");
    } else {
        $this->title = $title;
    }
}

但我建议你不要这样做。

On opencart 1.5.1.3 that work changing $this->config->get(“store_name”)$this->config->get(“config_name”)





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...