Currently, I am working on Facade Pattern which doesn't resolve through the application main Container class where i have implement bind method through the interface.
Index.php
use Bundles\Support\Facades\Route;
Route::get('/users', function () {
return 'Hello';
});
Facade:
Route facade
namespace Bundles\Support\Facades;
class Route extends Facade
{
/**
* Get the registered name of the component.
*
* #return string
*/
protected static function getFacadeAccessor()
{
return 'route';
}
}
Facade.php
namespace Bundles\Support\Facades;
use Bundles\Foundations\Application;
use RuntimeException;
class Facade
{
/**
* The application instance being facaded.
*/
protected static Application $app;
/**
* The resolved object instances.
*
* #var array
*/
protected static $resolvedInstance;
/**
* Indicates if the resolved instance should be cached.
*
* #var bool
*/
protected static $cached = true;
/**
* #param $method
* #param $args
*/
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (!$instance) {
throw new RuntimeException('A facade root has not been set.');
}
var_dump($method, $args, static::getFacadeAccessor());
Application::$app->bind(static::getFacadeAccessor(), $args, $method);
exit;
}
/**
* Get the root object behind the facade.
*
* #return mixed
*/
public static function getFacadeRoot()
{
return static::resolveFacadeInstance(static::getFacadeAccessor());
}
/**
* Get the registered name of the component.
*
* #throws \RuntimeException
*
* #return string
*/
protected static function getFacadeAccessor()
{
throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
}
/**
* Resolve the facade root instance from the container.
*
* #param string $name
*
* #return mixed
*/
protected static function resolveFacadeInstance($name)
{
if (isset(static::$resolvedInstance[$name])) {
return static::$resolvedInstance[$name];
}
if (static::$app) {
if (static::$cached) {
return static::$resolvedInstance[$name] = static::$app[$name];
}
return static::$app[$name];
}
}
}
Container.php
namespace Bundles\Containers;
use Bundles\Foundations\Application;
use Bundles\Interfaces\Application as ApplicationContract;
use Bundles\Routes\Route;
class Container implements ApplicationContract
{
/**
* #var Route
*/
public Route $router;
/**
* #var Application
*/
public static Application $app;
// register method called in Application constructor
public function register()
{
$this->router = new Route();
}
/**
* > The `bind` function takes a string as the first argument, and a second argument that can be either a string or a
* closure.
*
* #param string abstract The abstract type to bind to
* #param concrete the class name or a closure that returns an instance of the class
* #param shared whether the object should be shared or not
* #param null|mixed $concrete
* #param mixed $shared
*/
public function bind(string $abstract, $concrete = null, $shared = ''): void
{
var_dump($abstract, $concrete);
exit;
}
}
anyone can help on this?
Thanks in advance
Related
I am using a service within twig like this
{{ count_service.getCount(term.getId) }}
I want the service to use a repository function, repository function
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping;
class SynonymRepository extends EntityRepository
{
public function getCount($termId)
{
$qbSynonymType = $this->getEntityManager()->createQueryBuilder();
$synonymTypes = $qbSynonymType->select('synonymType.id, synonymType.type')
->from('AppBundle:SynonymType', 'synonymType')
->getQuery()->getResult();
$qb = $this->getEntityManager()->createQueryBuilder();
$count = [];
$qb->select('count(synonym.synonymId)')
->from('AppBundle:Synonym','synonym');
foreach($synonymTypes as $type) {
$count[$type['type']] = $qb
->where('synonym.term = :termId')
->andWhere('synonym.synonymType = :type')
->setParameter('termId', $termId)
->setParameter('type', $type['id'])
->getQuery()->getSingleScalarResult();
}
$qbTerm = $this->getEntityManager()->createQueryBuilder()->from('AppBundle:Term', 'term');
$count['parent'] = "NaN";
$count['children'] = "NaN";
return $count;
}
}
My service.yml looks like this
synonymrepository:
class: Doctrine\ORM\EntityRepository
factory: ["#doctrine.orm.entity_manager", getRepository]
arguments:
- AppBundle\Entity\SynonymType
term_count:
class: AppBundle\Services\TermCount
arguments:
- "#synonymrepository"
And finally my service looks like this
<?php
namespace AppBundle\Services;
use AppBundle\Repository\SynonymRepository;
class TermCount
{
private $repository;
public function __construct()
{
$this->repository = new SynonymRepository();
}
public function getCount($termId)
{
return $this->repository->getCount($termId);
}
}
When running this I am getting the following error
Type error: Too few arguments to function Doctrine\ORM\EntityRepository::__construct(), 0 passed in /var/www/html/src/AppBundle/Services/TermCount.php on line 15 and exactly 2 expected
I assume this is happening because extending SynonymRepository with the EntityRepository requires EntityManagerInterface $em and Mapping\ClassMetadata $class. But I am not sure how pass them to EntityRepository.
I was using this answer to get me here, lost on how to actually implement the finall bit.
Thanks for helping.
UPDATE
Entity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Table(name="synonym")
* #ORM\Entity(repositoryClass="AppBundle\Repository\SynonymRepository")
*/
class Synonym
{
/**
* #var int
* #ORM\Id()
* #ORM\Column(name="synonym_id", type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $synonymId;
/**
* #var Term
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Term", inversedBy="synonyms")
*/
protected $term;
/**
* #var SynonymType[]
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\SynonymType", inversedBy="synonyms")
*/
protected $synonymType;
/**
* #var int
* #ORM\Column(name="language_id", type="integer")
*/
protected $languageId;
/**
* #var string
* #ORM\Column(name="synonym", type="string", length=255)
*/
protected $synonym;
public function __construct()
{
// $this->synonymType = new ArrayCollection();
}
/**
* #return int
*/
public function getSynonymId(): int
{
return $this->synonymId;
}
/**
* #return Term
*/
public function getTerm(): Term
{
return $this->term;
}
/**
* #param int $termId
* #return Term
*/
public function setTerm(int $termId): Term
{
$this->term = $termId;
return $this->term;
}
/**
* #return SynonymType[]
*/
public function getSynonymType()
{
return $this->synonymType;
}
/**
* #param SynonymType $synonymType
* #return SynonymType
*/
public function setSynonymType(SynonymType $synonymType): SynonymType
{
$this->synonymType = $synonymType;
return $this->synonymType;
}
/**
* #return int
*/
public function getLanguageId(): int
{
return $this->languageId;
}
/**
* #param int $languageId
* #return Synonym
*/
public function setLanguageId(int $languageId): Synonym
{
$this->languageId = $languageId;
return $this;
}
/**
* #return string
*/
public function getSynonym(): string
{
return $this->synonym;
}
/**
* #param string $synonym
* #return Synonym
*/
public function setSynonym(string $synonym): Synonym
{
$this->synonym = $synonym;
return $this;
}
}
You need to use DI (Dependency injection) in your construct insted of using new cause as i see the erreur your SynonymRepository depends on other services
<?php
namespace AppBundle\Services;
use AppBundle\Repository\SynonymRepository;
class TermCount
{
private $repository;
public function __construct(SynonymRepository $synonymRepository)
{
$this->repository = $synonymRepository;
}
public function getCount($termId)
{
return $this->repository->getCount($termId);
}
}
I am trying to make rest api with dingo for laravel 5.3 . I have setup dingo on my project and created a api route like this for test .
$api->version('v1', function ($api) {
$api->get('hello',function (){
return "hello";
});
});
But when i run http://localhost:8000/api/hello
Then
{
message: "Call to undefined method Illuminate\Routing\Route::getUri()",
code: 1,
status_code: 500,
debug: {
line: 98,
file: "C:\xampp\htdocs\apiTest\vendor\dingo\api\src\Routing\Adapter\Laravel.php",
class: "Symfony\Component\Debug\Exception\FatalErrorException",
trace: [
"#0 {main}"
]
}
}
is shown .
i have searched and find this solution
Call to undefined method Illuminate\Routing\Route::get()
but when i used
use Illuminate\Support\Facades\Route;
then this problem shown
FatalErrorException in Laravel.php line 116:
Call to undefined method Illuminate\Support\Facades\Route::where()
This is the Laravel.php file
<?php
namespace Dingo\Api\Routing\Adapter;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Illuminate\Routing\RouteCollection;
use Dingo\Api\Contract\Routing\Adapter;
use Dingo\Api\Exception\UnknownVersionException;
class Laravel implements Adapter
{
/**
* Laravel router instance.
*
* #var \Illuminate\Routing\Router
*/
protected $router;
/**
* Array of registered routes.
*
* #var array
*/
protected $routes = [];
/**
* Old routes already defined on the router.
*
* #var \Illuminate\Routing\RouteCollection
*/
protected $oldRoutes;
/**
* Create a new laravel routing adapter instance.
*
* #param \Illuminate\Routing\Router $router
*
* #return void
*/
public function __construct(Router $router)
{
$this->router = $router;
}
/**
* Dispatch a request.
*
* #param \Illuminate\Http\Request $request
* #param string $version
*
* #return mixed
*/
public function dispatch(Request $request, $version)
{
if (! isset($this->routes[$version])) {
throw new UnknownVersionException;
}
$routes = $this->mergeExistingRoutes($this->routes[$version]);
$this->router->setRoutes($routes);
return $this->router->dispatch($request);
}
/**
* Merge the existing routes with the new routes.
*
* #param \Illuminate\Routing\RouteCollection $routes
*
* #return \Illuminate\Routing\RouteCollection
*/
protected function mergeExistingRoutes(RouteCollection $routes)
{
if (! isset($this->oldRoutes)) {
$this->oldRoutes = $this->router->getRoutes();
}
foreach ($this->oldRoutes as $route) {
$routes->add($route);
}
return $routes;
}
/**
* Get the URI, methods, and action from the route.
*
* #param mixed $route
* #param \Illuminate\Http\Request $request
*
* #return array
*/
public function getRouteProperties($route, Request $request)
{
return [$route->getUri(), $route->getMethods(), $route->getAction()];
}
/**
* Add a route to the appropriate route collection.
*
* #param array $methods
* #param array $versions
* #param string $uri
* #param mixed $action
*
* #return \Illuminate\Routing\Route
*/
public function addRoute(array $methods, array $versions, $uri, $action)
{
$this->createRouteCollections($versions);
$route = new Route($methods, $uri, $action);
$route->where($action['where']);
foreach ($versions as $version) {
$this->routes[$version]->add($route);
}
return $route;
}
/**
* Create the route collections for the versions.
*
* #param array $versions
*
* #return void
*/
protected function createRouteCollections(array $versions)
{
foreach ($versions as $version) {
if (! isset($this->routes[$version])) {
$this->routes[$version] = new RouteCollection;
}
}
}
/**
* Get all routes or only for a specific version.
*
* #param string $version
*
* #return mixed
*/
public function getRoutes($version = null)
{
if (! is_null($version)) {
return $this->routes[$version];
}
return $this->routes;
}
public function getIterableRoutes($version = null)
{
return $this->getRoutes($version);
}
/**
* Set the routes on the adapter.
*
* #param array $routes
*
* #return void
*/
public function setRoutes(array $routes)
{
$this->routes = $routes;
}
/**
* Prepare a route for serialization.
*
* #param mixed $route
*
* #return mixed
*/
public function prepareRouteForSerialization($route)
{
$route->prepareForSerialization();
return $route;
}
/**
* Gather the route middlewares.
*
* #param \Illuminate\Routing\Route $route
*
* #return array
*/
public function gatherRouteMiddlewares($route)
{
return $this->router->gatherRouteMiddlewares($route);
}
}
Has there any solution ?
Thanks
Use $route->uri()
insted of $route->getUri()
create a pull request to dingo api after updating this
I want to pass $this into the sub objects I create on construct However when I dump it I get a **RECURSION** flag.
<?php
namespace Cortana\Framework\System;
use Cortana\Framework\System\ApiAccessor\CacheApiAccessor;
use Cortana\Framework\System\ApiAccessor\ConfigurationApiAccessor;
use Cortana\Framework\System\ApiAccessor\DatabaseApiAccessor;
use Cortana\Framework\System\ApiAccessor\EventsManagerApiAccessor;
use Cortana\Framework\System\ApiAccessor\FilesystemApiAccessor;
use Cortana\Framework\System\ApiAccessor\LocaleApiAccessor;
use Cortana\Framework\System\ApiAccessor\LogApiAccessor;
use Cortana\Framework\System\ApiAccessor\SessionApiAccessor;
use Cortana\Framework\System\ApiAccessor\TranslateApiAccessor;
/**
* System Handler Instance
*
* #author root
*/
class SystemHandler
{
/**
* Development Environment Flag
*
* #var string
*/
const ENV_DEVELOPMENT = 'DEVELOPMENT';
/**
* Staging Environment Flag
*
* #var string
*/
const ENV_STAGING = 'STAGING';
/**
* Test Environment Flag
*
* #var string
*/
const ENV_TEST = 'TEST';
/**
* Production Environment Flag
*
* #var string
*/
const ENV_PRODUCTION = 'PRODUCTION';
/**
* Configuration api accessor instance
*
* #var ConfigurationApiAccessor
*/
protected $configurationApiAccessor;
/**
* Database api accessor instance
*
* #var DatabaseApiAccessor
*/
protected $databaseApiAccessor;
/**
* Translation api accessor instance
*
* #var TranslateApiAccessor
*/
protected $translateApiAccessor;
/**
* Cache api accessor instance
*
* #var CacheApiAccessor
*/
protected $cacheApiAccessor;
/**
* Locale api accessor instance
*
* #var LocaleApiAccessor
*/
protected $localeApiAccessor;
/**
* Events Manager api accessor instance
*
* #var EventsManagerApiAccessor
*/
protected $eventsManagerApiAccessor;
/**
* Log api accessor instance
*
* #var LogApiAccessor
*/
protected $logApiAccessor;
/**
* Session api accessor instance
*
* #var SessionApiAccessor
*/
protected $sessionApiAccessor;
/**
* Filesystem api accessor instance
*
* #var FilesystemApiAccessor
*/
protected $filesystemApiAccessor;
/**
* Array of Loaded Modules
*
* #var array
*/
protected $loadedModules=[];
/**
* System Environment
*
* #var string
*/
protected $environment;
/**
* System Handler Constructor. Loads Accessors
*/
public function __construct()
{
$this->filesystemApiAccessor = new FilesystemApiAccessor();
$this->configurationApiAccessor = new ConfigurationApiAccessor();
$this->databaseApiAccessor = new DatabaseApiAccessor();
$this->cacheApiAccessor = new CacheApiAccessor();
$this->eventsManagerApiAccessor = new EventsManagerApiAccessor();
$this->localeApiAccessor = new LocaleApiAccessor();
$this->logApiAccessor = new LogApiAccessor();
$this->sessionApiAccessor = new SessionApiAccessor();
$this->translateApiAccessor = new TranslateApiAccessor();
}
public function build()
{
}
/**
* Set the system environment
*
* #param string $environment the system environment
* #return SystemHandler
*/
public function setEnvironment($environment)
{
$this->environment = $environment;
return $this;
}
/**
* Return the system environment
*
* #return string the system environment
*/
public function getEnvironment()
{
return $this->environment;
}
/**
* Set the system loaded modules
*
* #param array $loadedmodules array of loaded system modules
* #return SystemHandler
*/
public function setLoadedModules(array $loadedmodules)
{
$this->loadedModules = $loadedmodules;
return $this;
}
/**
* Add a module as a loaded module
*
* #param string $module module to add as a loaded module
* #return SystemHandler
*/
public function addLoadedModule($module)
{
$this->loadedModules[] = $module;
return $this;
}
/**
* Clear loaded modules
*
* #return SystemHandler
*/
public function clearLoadedModule()
{
$this->loadedModules = [];
return $this;
}
/**
* Set the configuration api accessor instance
*
* #param ConfigurationApiAccessor $configurationApiAccessor the configuration api accessor instance
* #return SystemHandler
*/
public function setConfigurationApiAccessor(ConfigurationApiAccessor $configurationApiAccessor)
{
$this->configurationApiAccessor = $configurationApiAccessor;
return $this;
}
/**
* Return the configuration api accessor instance
*
* #return ConfigurationApiAccessor the configuration api accessor instance
*/
public function getConfigurationApiAccessor()
{
return $this->configurationApiAccessor;
}
/**
* Set the database api accessor instance
*
* #param DatabaseApiAccessor $databaseApiAccessor the database api accessor instance
* #return SystemHandler
*/
public function setDatabaseApiAccessor(DatabaseApiAccessor $databaseApiAccessor)
{
$this->databaseApiAccessor = $databaseApiAccessor;
return $this;
}
/**
* Return the database api accessor instance
*
* #return DatabaseApiAccessor the database api accessor instance
*/
public function getDatabaseApiAccessor()
{
return $this->databaseApiAccessor;
}
/**
* Set the translation api accessor instance
*
* #param TranslateApiAccessor $translateApiAccessor the translation api accessor instance
* #return SystemHandler
*/
public function setTranslateApiAccessor(TranslateApiAccessor $translateApiAccessor)
{
$this->translateApiAccessor = $translateApiAccessor;
return $this;
}
/**
* Return the translation api accessor instance
*
* #return TranslateApiAccessor the translation api accessor instance
*/
public function getTranslateApi()
{
return $this->translateApiAccessor;
}
/**
* Set the cache api accessor instance
*
* #param CacheApiAccessor $cacheApiAccessor the cache api accessor instance
* #return SystemHandler
*/
public function setCacheApiAccessor(CacheApiAccessor $cacheApiAccessor)
{
$this->cacheApiAccessor = $cacheApiAccessor;
return $this;
}
/**
* Return the cache api accessor instance
*
* #return CacheApiAccessor the cache api accessor instance
*/
public function getCacheApiAccessor()
{
return $this->cacheApiAccessor;
}
/**
* Set the locale api accessor instance
*
* #param LocaleApiAccessor $localeApiAccessor the locale api accessor instance
* #return SystemHandler
*/
public function setLocaleApiAccessor(LocaleApi $localeApiAccessor)
{
$this->localeApiAccessor = $localeApiAccessor;
return $this;
}
/**
* Return the locale api accessor instance
*
* #return LocaleApiAccessor the locale api accessor instance
*/
public function getLocaleApiAccessor()
{
return $this->localeApi;
}
/**
* Set the events manager api accessor instance
*
* #param EventsManagerApiAccessor $eventsManagerApiAccessor the events manager api accessor instance
* #return SystemHandler
*/
public function setEventsManagerApiAccessor(EventsManagerApiAccessor $eventsManagerApiAccessor)
{
$this->eventsManagerApiAccessor = $eventsManagerApiAccessor;
return $this;
}
/**
* Return the events manager api accessor instance
*
* #return EventsManagerApiAccessor the events manager api accessor instance
*/
public function getEventsManagerApiAccessor()
{
return $this->eventsManagerApiAccessor;
}
/**
* Set the logger api accessor instance
*
* #param LogApiAccessor $logApiAccessor the log api accessor instance
* #return SystemHandler
*/
public function setLogApi(LogApiAccessor $logApiAccessor)
{
$this->logApiAccessor = $logApiAccessor;
return $this;
}
/**
* Return the log api accessor instance
*
* #return LogApiAccessor the log api accessor instance
*/
public function getLogApi()
{
return $this->logApiAccessor;
}
/**
* Set the session api accessor instance
*
* #param SessionApiAccessor $sessionApiAccessor the session api accessor instance
* #return SystemHandler
*/
public function setSessionApiAccessor(SessionApiAccessor $sessionApiAccessor)
{
$this->sessionApiAccessor = $sessionApiAccessor;
return $this;
}
/**
* Return the session api accessor instance
*
* #return SessionApiAccessor the session api accessor instance
*/
public function getSessionApiAccessor()
{
return $this->sessionApiAccessor;
}
/**
* Set the filesystem api accessor instance
*
* #param FilesystemApiAccessor $filesystemApiAccessor the filesystem api accessor instance
* #return SystemHandler
*/
public function setFilesystemApiAccessor(FilesystemApiAccessor $filesystemApiAccessor)
{
$this->filesystemApiAccessor = $filesystemApiAccessor;
return $this;
}
/**
* Return the filesystem api accessor instance
*
* #return FilesystemApiAccessor the filesystem api accessor instance
*/
public function getFilesystemApiAccessor()
{
return $this->filesystemApiAccessor;
}
}
when you create a new class that extends other class, you don't need to pass anything to the constructor, it will be automatically available in the subclass as long as those methods/properties are public or protected. If they are private, you cannot use them in subclass. If you want to use protected/public properties or methods from parent class in your subclass, use them as if you were in the parent class.
class parent{
protected $foo = 'foobar';
protected function get_foo(){
return $this->foo;
}
}
class subclass extends parent{
protected $bar;
public function __construct(){
$this->bar = $this->get_foo();
}
public function get_bar(){
return $this->bar;
}
}
$baz = new bar;
echo $baz->get_bar();
// outputs 'foobar'
I have a class: ClassA(), i need the Doctrine Service $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');.
I try implements the interface ServiceManagerAwareInterface, but the functions, getServiceLocator() and setServiceLocator(ServiceLocatorInterface $serviceLocator) not work.
Someone used the ServiceLocator outside Controller class in ZF2? It's possible?
<?php
namespace DbSession\Service;
use Zend\Session\SaveHandler\SaveHandlerInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
/**
* Description of SessionDB
*
* #author rab
*/
class SessionDB implements SaveHandlerInterface, ServiceLocatorAwareInterface {
use ServiceLocatorAwareTrait;
/**
* Session Save Path
*
* #var string
*/
protected $sessionSavePath;
/**
* Session Name
*
* #var string
*/
protected $sessionName;
/**
* Lifetime
* #var int
*/
protected $lifetime;
/**
* Constructor
*
*/
public function __construct() {
}
/**
* Open the session
*
* #return bool
*/
public function open($savePath, $name) {
echo "open session";
}
/**
* Close the session
*
* #return bool
*/
public function close() {
echo "close session";
}
/**
* Read the session
*
* #param int session id
* #return string string of the sessoin
*/
public function read($id) {
echo "read session";
}
/**
* Write the session
*
* #param int session id
* #param string data of the session
*/
public function write($id, $data) {
$this->getServiceLocator()->get('');
echo "write";
}
/**
* Destoroy the session
*
* #param int session id
* #return bool
*/
public function destroy($id) {
echo "destroy session";
}
/**
* Garbage Collector
*
* #param int life time (sec.)
* #return bool
*/
public function gc($maxlifetime) {
echo "gc session";
}
}
The easiest way would be to use the ServiceLocatorAwareTrait (part of ZF2). If you do use that make sure your class implements ServiceLocatorAwareInterface (you don't actually have to implement it as the trait does that for you, but you do have to add it to your class' implements clause).
So you get something like this:
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
class ClassA implements ServiceLocatorAwareInterface {
use ServiceLocatorAwareTrait;
}
Then you can just call $this->getServiceLocator() to get a hold of a servicelocator instance.
However if you just need the Doctrine entitymanager it's better practice to just inject this one dependency instead of injecting the ServiceLocator.
Finally solved the problem. My class SessionDatabase() is correct. My instance was wrong.
Implements class:
class SessionDatabase implements SaveHandlerInterface, ServiceLocatorAwareInterface {
use ServiceLocatorAwareTrait;
public function write($id, $data) {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
}
Instance:
private function initDbSession(MvcEvent $e) {
$serviceManager = $e->getApplication()->getServiceManager();
$saveHandler = new SessionDatabase();
$saveHandler->setServiceLocator($serviceManager);
}
Thanks everyone that helped!!! :D
I have been trying to use the _forward method to access a method in my IndexController from another controller, but it won't seem to work. I have tried:
$this->_forward('permissions', 'Index')
$this->_forward('permissions', 'index')
$this->_forward('permissions', 'IndexController')
$this->_forward('permissions', 'indexcontroller')
None of which have worked. Here is my code.
Controller
class IndexController extends Zend_Controller_Action
{
/**
* facebookConfig
*
* #var mixed
* #access protected
*/
protected $facebookConfig;
/**
* signed_request
*
* #var mixed
* #access protected
*/
protected $signed_request;
/**
* facebookConfig
*
* #var mixed
* #access protected
*/
protected $permissions;
/**
* init function.
*
* #access public
* #return void
*/
public function init()
{
// get the model
$this->app = new Application_Model_Admin();
// get config data
$this->facebookConfig = $this->app->configData();
// get the apps permissions
$this->permissions = $this->permissions();
// get the data for the head
$data = $this->app->configData();
if(empty($data->ogimage))
$data->ogimage = '';
// set the page title
$this->view->headTitle($data->title, 'PREPEND');
// set the meta data
$this->view->headMeta()->setName('fb:app_id', $data->appid);
$this->view->headMeta()->setName('og:type', $data->ogtype);
$this->view->headMeta()->setName('og:title', $data->ogtitle);
$this->view->headMeta()->setName('og:description', $data->ogdesc);
$this->view->headMeta()->setName('og:url', $data->applink);
$this->view->headMeta()->setName('og:image', $data->ogimage);
}
/**
* permissions function.
*
* #access public
* #return void
*/
public function permissions(){
// return the permissions
return 'publish_stream, read_stream, friends_likes';
}
}
Second Controller
<?php
class ThanksController extends Zend_Controller_Action
{
/**
* facebookConfig
*
* #var mixed
* #access protected
*/
protected $permissions;
/**
* init function.
*
* #access public
* #return void
*/
public function init()
{
// get the model
// get the permissions
$this->permissions = $this->_forward('permissions', 'index');
print_r('<pre>');var_dump($this->_forward('permissions', 'index'));print_r('</pre>');die;
}
}
_forward is used only to call controller actions, not regular methods
_forward('index') actually refers to method indexAction()
Change this:
public function permissions(){
// return the permissions
return 'publish_stream, read_stream, friends_likes';
}
to this:
public function permissionsAction(){
// return the permissions
return 'publish_stream, read_stream, friends_likes';
}
I wasn't thinking particularly clearly, instead I just put the code in a model and accessed the data from their.