This is my route,
define [
'apps/home/index/index'
'apps/home/edit/index'
'apps/home/about/aboutUs'
'apps/home/about/jobs'
],
(HomeIndex, EditIndex, aboutUsIndex, jobsIndex) ->
class Router extends Marionette.AppRouter
routes :
'' : 'indexPage'
'index' : 'indexPage'
'edit' : 'editApp'
'aboutUs' : 'aboutUsPage'
'jobs' : 'jobsPage'
indexApp : () ->
#homeIndex = new HomeIndex()
App.contentArea.show #homeIndex
editApp : () ->
#homeIndex = new EditIndex()
App.contentArea.show #homeIndex
aboutUsPage : () ->
#homeIndex = new aboutUsIndex()
App.contentArea.show #homeIndex
jobsPage : () ->
#homeIndex = new jobsIndex()
App.contentArea.show #homeIndex
But when the route load (when it opens index only), it will load all the file that doesn't have to load now.
So, I want to change to like this, so that reduce loading time.
define [
'apps/home/index/index'
],
(HomeIndex) ->
class Router extends Marionette.AppRouter
routes :
'' : 'indexPage'
'index' : 'indexPage'
'edit' : 'editApp'
'aboutUs' : 'aboutUsPage'
'jobs' : 'jobsPage'
indexApp : () ->
#homeIndex = new HomeIndex()
App.contentArea.show #homeIndex
editApp : () ->
# LOAD 'apps/home/edit/index' file, if it has not loaded
#homeIndex = new EditIndex()
App.contentArea.show #homeIndex
aboutUsPage : () ->
# LOAD 'apps/home/about/aboutUs' file, if it has not loaded
#homeIndex = new aboutUsIndex()
App.contentArea.show #homeIndex
jobsPage : () ->
# LOAD 'apps/home/about/jobs' file, if it has not loaded
#homeIndex = new jobsIndex()
App.contentArea.show #homeIndex
Is this possible? If so, how should I do to make, please advice me.
Yes This is Possible You can do this using Require.js,All you need to do is just use this library in your project and make your app structure like one he demand...
Related
I have a code:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
[..]
This is a property from translation (KNP translatable). I tried use:
translations.name - label is sortable, but values are missing
name or translate.name - label is not sortable, but values are ok
I don't have any idea how I should to do this. Maybe someone here can help me?
Did you try $listMapper->add('name',null, array('sortable'=>true)) ?
Ok, I made it.
1) Create abstract admin class:
use Sonata\AdminBundle\Admin\AbstractAdmin as BaseAbstractAdmin;
abstract class AbstractAdmin extends BaseAbstractAdmin { .. }
2) Use this class in your admin classes:
class UserAdmin extends AbstractAdmin { .. }
3) Add this to your column definition:
->add(
'fieldName',
null,
[
'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'id'],
'sort_parent_association_mappings' => [],
]
)
4) Add this method to your abstract admin class:
protected function prepareQueryForTranslatableColumns($query)
{
$currentAlias = $query->getRootAliases()[0];
$locale = $this->request->getLocale();
$parameters = $this->getFilterParameters();
$sortBy = $parameters['_sort_by'];
$fieldDescription = $this->getListFieldDescription($sortBy);
$mapping = $fieldDescription->getAssociationMapping();
$entityClass = $mapping['targetEntity'] ?: $this->getClass();
if ($mapping) {
$mappings = $fieldDescription->getParentAssociationMappings();
$mappings[] = $mapping;
foreach ($mappings as $parentMapping) {
$fieldName = $parentMapping['fieldName'];
$query->leftJoin($currentAlias . '.' . $fieldName, $fieldName);
$currentAlias = $fieldName;
}
}
$query
->leftJoin(
$currentAlias . '.translations',
'tr',
'with',
'tr.locale = :lang OR
(NOT EXISTS(SELECT t.id FROM ' . $entityClass . 'Translation t WHERE t.translatable = tr.translatable AND t.locale = :lang)
AND tr.locale = :lang_default)'
)
->addOrderBy('tr.name', $parameters['_sort_order'])
->setParameter(':lang', $locale)
->setParameter(':lang_default', 'en');
return $query;
}
I use JOIN to get translations for currently selected locale and, if translation doesn't exist yet for current locale, I add translation for default locale (it is a reason for use NOT EXIST).
5) Add this method to your admin class:
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
if ('list' === $context) {
$parameters = $this->getFilterParameters();
$sortBy = $parameters['_sort_by'];
if (in_array($sortBy, ['fieldName', 'fieldName.fieldName2', 'fieldName3', ..])) {
$query = parent::prepareQueryForTranslatableColumns($query);
}
}
return $query;
}
Late answer but I was having the same problem.
The easiest solution for me was to set the right property mapping like this:
$listMapper->add(
'translations',
null,
[
'sortable' => true,
'associated_property' => 'name',
'sort_field_mapping' => [
'fieldName' => 'name',
],
'sort_parent_association_mappings' => [
['fieldName' => 'translations'],
],
]
);
I'm new to slim. I ran into an error telling me the callable controller does not exist. However my other controller (HomeController) does work. I'm sure I am doing something stupid but I can't figure out what.
Error Message
Type: RuntimeException
Message: Callable JoeyD473\RPG_Tools\controllers\traveller\UniverseCreationControllercreateUniverse does not exist
File: C:\Users\Joey\Web\JRD_Traveller_Tools\vendor\slim\slim\Slim\CallableResolver.php
Line: 90
Project Structure
\public
index.php
.htaccess
\src
\app
\controllers
BaseController.php
HomeController.php
\traveller
UniverseCreationController.php
\model
\views
config.php
container.php
routes.php
composer.json
"autoload": {
"psr-4": {
"JoeyD473\\RPG_Tools\\models\\": "src/app/model",
"JoeyD473\\RPG_Tools\\controllers\\": "src/app/controllers"
}
},
container.php
$container = $app->getContainer();
$container['view'] = new \Slim\Views\PhpRenderer(APP.'views/');
$container['db'] = function($c){
$settings = $c->get('settings')['db'];
$db = new \Aura\Sql\ExtendedPdo($settings['vendor'].':host='.$settings['host'].';dbname='.$settings['db_name'],$settings['username'],$settings['password']);
return $db;
};
$container['HomeController'] = function($container){
return new \JoeyD473\RPG_Tools\controllers\HomeController;
};
$container['UniverseCreationController'] = function($container){
return new \JoeyD473\RPG_Tools\controllers\traveller\UniverseCreationController;
};
routes.php
$app->get('/',JoeyD473\RPG_Tools\controllers\HomeController::class.':home');
$app->get('/api',JoeyD473\RPG_Tools\controllers\HomeController::class.':sw_api');
$app->get('/temp',JoeyD473\RPG_Tools\controllers\HomeController::class.':temp');
$app->get('/universe/create_new_universe',JoeyD473\RPG_Tools\controllers\traveller\UniverseCreationController::class.'createUniverse');
UniverseCreationController.php
namespace JoeyD473\RPG_Tools\controllers\traveller;
use JoeyD473\RPG_Tools\controllers\BaseController;
use JoeyD473\RPG_Tools\models\traveller\universe\Universes;
class UniverseCreationController extends BaseController
{
public function createUniverse($request,$response)
{
return $this->container->view->render($response,'travellers/universe/create_universe.phtml');
}
public function generateUniverse($request,$response)
{
$universe = new Universes($this->db);
return 'generateSector';
}
}
You've missed a colon (:) in your last route
\traveller\UniverseCreationController::class.'createUniverse');
^^^
You could also use the array syntax for this.
[YourClass::class, 'yourMethod']
I'm creating a page in CakePHP, i'm trying to translate the url. What i want is to translate the controller name so let says i have this url domain/da/product then it should translate it into danish so it became domain/da/produkt.
I've written my own url method in AppHelper but i have problems with accessing the model for translation. When i search for accessing model from helper, people are against doing it that way.
So what will be a proper way to do this. When the user use the link i need to make a lookup where i translate it back to domain/da/product.
Here is the Apphelper code
App::uses('Helper', 'View');
App::import("Model", "ControllerTranslation");
class AppHelper extends Helper {
public function url($url = null, $full = false) {
$Model = new ControllerTranslation();
$lang = Configure::read('Config.language');
$controller = $Model->find("first",array("conditions"=> array("ControllerTranslation.translation = "=> $url['controller'],"ControllerTranslation.language" => $lang)));
if (count($controller))
{
$url['controller'] = $controller["ControllerTranslation"]["translation"];
}
return parent::url($url, $full);
}
if you want the url that has translation = $url['controller'] and language = $lang then you should use syntax:
$controller = $Model->find("first",
array("conditions"=>
array(
"ControllerTranslation.translation" => $url['controller'],
"ControllerTranslation.language" => $lang
)
)
);
i create my component like this
<?php
class UtilComponent extends Object
{
function strip_and_clean( $id, $array) {
$id = intval($id);
if( $id < 0 || $id >= count($array) ) {
$id = 0;
}
return $id;
}
}
and use it like this
var $name = 'Books';
var $uses = array();
var $components = array('Util');
public function index($id = 0){
$this -> set('page_heading','Packt Book Store');
$book=array(
'0'=>array(
'bookTitle' =>'Object Oriented Programming with PHP5',
'author' =>'Hasin Hayder',
'isbn' => '1847192564',
'releaseDate' => 'December 2007'
),
'1'=>array(
'bookTitle' =>'Building Websites with Joomla! v1.0',
'author' =>'Hagen Graf',
'isbn' => '1904811949',
'releaseDate' => 'March 2006'
),
);
$id = $this->Util->strip_and_clean( $id, $book);
$this->set('book',$book[$id]);
$this->pageTitle='Welcome to the Packt Book Store!';
}
but i got this error
**call_user_func_array() expects parameter 1 to be a valid callback, class 'UtilComponent' does not have a method 'initialize' [CORE\Cake\Utility\ObjectCollection.php, line 130]**
I believe a component should extend Component not Object:
class UtilComponent extends Component
{
}
The component will then inherit the initialize() method.
Got a similar issue.
Apart from the error message ... does not have a method 'initialize' ..., one more message was there ... does not have a method 'startup' ....
The issue was I created the component file inside the Controller directory instead of Controller/Component.
I also face same issue like
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'ImageComponent' does not have a method 'initialize' [CORE\Cake\Utility\ObjectCollection.php, line 128]
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'ImageComponent' does not have a method 'beforeRender' [CORE\Cake\Utility\ObjectCollection.php, line 128]
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'ImageComponent' does not have a method 'shutdown' [CORE\Cake\Utility\ObjectCollection.php, line 128]
Solution is :
Add Image component into controller/component then
change class ImageComponent extends object { ... }
with class ImageComponent extends Component { ... }
I'm out of ideas here is my controller:
class GoogleNewsController extends AppController {
var $name = 'GoogleNews';
var $uses = array('GoogleNews', 'SavedNews');
var $helpers = array('Html','Form');
function index() {
$saved = $this->set('news',$this->GoogleNews->find('all'));
Im reading data from 'GoogleNews' and they are in my array. Array looks like this:
array(10) {
[0]=>
array(1) {
["GoogleNews"]=>
array(12) {
["title"]=>
string(32) "FIFA 11 für 25,49€ aus Jersey"
["link"]=>
string(54) "http://feedproxy.google.com/~r/myDealZ/~3/HuNxRhQJraQ/"
["pubDate"]=>
string(31) "Mon, 06 Dec 2010 10:53:22 +0000"
["creator"]=>
string(5) "admin"
["guid"]=>
array(2) {
["value"]=>
string(30) "http://www.mydealz.de/?p=15137"
["isPermaLink"]=>
string(5) "false"
}
["description"]=>
string(355) "
And I want to save elements to my database 'SavedNews'
I need to save description and title.
Can anybody tell me how should I write it?
$this->SavedNews->set(array('description' =>$this->GoogleNews->find('description')));
Is this a solution?
Its only way that it works, but it puts null values to my columns.
If I'm understanding your requirements correctly, the following should work.
In your controller:
class NewsController extends AppController
{
function import_from_google()
{
// Load the GoogleNews model and retrieve a set of its records
$this->loadModel('GoogleNews');
$newsFromGoogle = $this->GoogleNews->find('all');
$this->loadModel('SavedNews');
foreach ($newsFromGoogle as $_one) {
// Reset the SavedNews model in preparation for an iterated save
$this->SavedNews->create();
// Assemble an array of input data appropriate for Model::save()
// from the current GoogleNews row
$saveable = array(
'SavedNews' => array(
'title' => $_one['GoogleNews']['title'],
'description' => $_one['GoogleNews']['description']
)
);
// send the array off to the model to be saved
$this->SavedNews->save($saveable);
}
$this->autoRender = false; // No need to render a view
}
}
Refine as desired/required. For example, the iterated save operations should happen in the SavedNews model, rather than in the controller. The above code also has no fault-tolerance.
HTH.