Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to implement phalcon classes?

I sees many pages in the Phalcon's document said implement but none of them show how to implement.

For example: URL class.

I was extended my URL generator class in app/Extend/Phalcon/Mvc/Url.php

<?php

namespace Extend\Phalcon\Mvc;

class Url extends \Phalcon\Mvc\Url
{





    /**
     * Returns the prefix for all the generated urls. By default /
     *
     * @return string
     */
    public function getBaseUri()
    {
        return 'hey';
    }


}

Now, i want to use it properly in my controller like this. echo $this->url->getBaseUri();. But it didn't work.

So, i replaced namespace\class in app/config/services.php from use Phalcon\Mvc\Url as UrlResolver; to use Extension\Phalcon\Mvc\Url as UrlResolver;

But i'm getting this error Fatal error: Class 'Extension\Phalcon\Mvc\Url' not found



34.7k
Accepted
answer

Hi * Fatal error: Class 'Extension\Phalcon\Mvc\Url' not found* are you sure loader it



3.6k

Ok this case is my fault that i use wrong namespace. But please show me example how to implement another class (extend class or whatever) that Phalcon said in the document.


Lets begin with Tag class. The tag class can call with chaining method in controller (and view, maybe, i'm not sure).

namespace Extend\Phalcon;

class Tag extends \Phalcon\Tag
{

    public static function linkTo($parameters, $text=null){ 
        return 'no link';
    }

}

I had already add this in app/config/services.php

$di->set('tag', function() {
    $tag = new \Extend\Phalcon\Tag();
    return $tag;
}, true);

I can call $this->tag->linkTo(&#039;somewhere&#039;, &#039;go to somewhere&#039;); successfully. But i cannot call to \Phalcon\Tag::linkTo(&#039;whereever&#039;, &#039;some where else&#039;); and got no link text.