Extending the Table Class in Qooxdoo doesn't works? - extend

I have a custom class that looks like this:
qx.Class.define('test.Table2', {
extend: qx.ui.table.Table,
construct: function(model){
this.base(arguments);
}
});
What happens?
If I use the qx.ui.table.Table with a model it shows data. If I change to test.Table2 then it shows an empty table with empty col names too. only a little bar.
How do I extend it properly?

You should pass all parameters to base class constructor:
this.base(arguments, model);

Related

Correct way to extend Prestashop 1.7

In PS 1.7 documentation, we can read multiple time that the PS override system is not recommended, an it's not allowed to publish module in the PS marketplace.
We have to only use hooks, and extend existing class, and I understood why.
But how to use the extended class instead of the core one in our custom theme ?
Let use a example :
I want to add a custom field for categories.
In a module I extend the CategoryCore class :
class Category extend CategoryCore{
private $bottom_description
...
}
Then to add the field in the category's admin page I can use some hook like displayBackOfficeCategory and actionBeforeAddCategory.
But I'm not sure for the front : the new variable have to be accessible in some theme templates files.
In my custom theme, in the category.tpl template, $category->bottom_description is undefined.
Fix this issue by overriding the CategoryController is easy,but how to do this only with hook ?
The only way I found is to use the actionFrontControllerSetMedia hook, like this :
function HookActionFrontControllerSetMedia(){
// get my custom Category object base on url
this->context->smarty->assign(["category_bottom_description"=>$category->buttom_description]);
}
This look tricky, and my new field is still not accessible in other context.
So what is the proper way to get this property available in my custom them ?
Ideally, the new property should be available every time we found a category object, like this : $category->bottom_description.
Do not forget to define a new field at category class because at the front you have not a class instance but an array which is converted within ObjectPresenter class. So follow this way. Extend your Category class and add all necessary definitions
class Category extends CategoryCore
{
public $bottom_description;
public function __construct($idCategory = null, $idLang = null, $idShop = null)
{
Category::$definition['fields']['bottom_description'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
$this->bottom_description = 'bottom_description'; // just to add demo data
parent::__construct($idCategory, $idLang, $idShop);
}
}
and then the field bottom_description will be available in the category.tpl but like an array {$category.bottom_description}. Hope it will help you.

Passing array from AuthController to login view in Laravel 5

Am having a problem passing an array from Laravel's AuthController to auth.login view. What am trying to do is retrieve data from News model and send it to the view. I know how to use eloquent to retrieve data, passing from the controller to the view is my problem as I cannot see the how/where Laravel is rendering the view.
Add an array as second parameter to the view method when returning it in the controller.
return view('greetings', ['name' => 'Victoria']); // in controller
Then in your view, you should be able to access the variable $name which should be equal to Victoria
var_dump($name); // in view
More in the documentation
I solved it by passing the variable through the Controller on the redirect method.
I am not entirely sure what the objective is here, but you said:
I cannot see the how/where Laravel is rendering the view.
So to answer that:
Laravel's AuthController pulls in a trait AuthenticatesAndRegistersUsers which itself pulls in a few other traits, one being AuthenticatesUsers and another being RegistersUsers.
In AuthenticatesUsers you will find a method like so:
/**
* Show the application login form.
*
* #return \Illuminate\Http\Response
*/
public function showLoginForm()
{
$view = property_exists($this, 'loginView')
? $this->loginView : 'auth.authenticate';
if (view()->exists($view)) {
return view($view);
}
return view('auth.login');
}
There is likewise a similar method in the RegistersUsers trait.
This is where the AuthController returns its views.
If you need to tweak this behavior, or return the view with some data, you could override these methods in your controller, if this is really the best solution to your given situation.
Meanwhile I found a better way to do that.
You can override the showRegistrationForm() method in AuthController.php and pass along the data you want to use in the view. Ex.:
public function showRegistrationForm()
{
$results = Model::all();
return view('auth.register', ['results' => $results]);
}

add new item to CHtml in yii

I work Yii with doctrine 2. I have a problem, datetime in doctrine 2 is an object of DateTime class, and I can't update it with regular methods of CHtml or form.
How can I add new item in CHtml that can handle this situation.
--Best Regards
Moe Far
You can extend the CHtml class and add your own functions. The code should look something like this:
class MyHtml extends CHtml {
// add you own logic or override CHtml functions
public static function myFunction() {
return 'yeah!';
}
}
You can then use MyHtml::myFunction() and also use all the standard CHtml functions.
Take a look at this question for more info on extending classes in Yii: How to extend Yii framework classes and where to place the files

Lithium Framework Architecture - Call One Controller from Another

I'm working on a web app using the Lithium Framework with a MongoDB database.
On one page of the application - I want to display data from multiple object types. I understand the concept of relationships (i.e. belongsTo, hasMany, etc.) between models. But, my questions has to do with Controller relationships.
For example, assume I have two objects named "People" and "Companies". I want to show specific information about Companies on a "people" view. I have done the following:
1) In the "People" model, I've added the following line:
public $belongsTo = array('Companies');
2) In the "PeopleController" file, I've also included a reference to the Companies Model, such as:
use app\models\Companies;
Now, within the PeopleController, I want to call a method in the CompaniesController file.
Do I access this by directly calling the CompaniesController file? Or, do I have to go thru the Company model.
In either case, I'll need help with the syntax. I'm having rouble figuring out the best way this should be called.
Thanks in advance for your help!
You should rethink your structure - you controller method should really grab all the resources you need for that view, it doesn't matter what they are.
So if you have a url '/people/bob' and you want to get the company data for Bob just add that to the view method of your People controller. Something like
People::first(array('conditions' => array('name' => 'Bob'), 'with' => 'Companies'));
You could instantiate a CompaniesController (maybe passing in $this->request to the 'request' option in the process) and then call the method in it. However, a better way to organize it is to move the common functionality from CompaniesController to Companies and call it from both places.
use app\models\Companies does not really make a "reference." It simply indicates that Companies really means app\models\Companies. I think an "alias" is a better way to think of it. See http://php.net/manual/en/language.namespaces.importing.php.
Example:
// in app/models/Companies.php
namespace app\models;
class Companies extends \lithium\data\Model {
public static function doSomething() {
// do something related to companies.
}
}
// in app/controllers/CompaniesController.php
namespace app\controllers;
use app\models\Companies;
class CompaniesController extends \lithium\action\Controller {
public function index() {
$result = Companies::doSomething();
return array('some' => 'data', 'for' => 'the view');
}
}
// in app/controllers/PeopleController.php
namespace app\controllers;
use app\models\Companies;
class PeopleController extends \lithium\action\Controller {
public function index() {
$result = Companies::doSomething();
return array('some' => 'data', 'for' => 'the view');
}
}

fluent nhibernate polymorphism. how to check for type of class

I have an Icon which has a Content (one to one) relationship.
public class Icon
{
public virtual Content Content {get; set;}
}
By default, it is lazy loaded which is what I want.
However, at some point in the code, I need to check what kind of Content is, Content being polymorphic, something like
if(icon.Content is TextContent)
{
...
}
Icon is part of another association and it is automatically obtained by the NHibernate, I do not get it manually.
What is the recommended way of checking for the actual type in this situation?
I can have a specific property like ContentType which will be an enum in order to identify the actual content type, but I am looking to know if there's a different way.
If you want to do that kind of check, you have to remove the proxy from the property.
There is a few ways to do it:
If you have access to the session call:
session.PersistenceContext.Unproxy(icon.Content);
Implement a virtual method (in a base class if possible) that forces the removal of the proxy by returning the instance with the proper type.
public virtual U As<U>() where U : YourType {
return this as U;
}
Disable the lazy initialization of the property.
This is very similar to another recent question.
To add to csanchez's list, a fourth method is to add a Self property to the Content base class that returns the un-proxied type:
public virtual void Self
{
get { return this; }
}
And a fifth method is to use 'lazy="no-proxy"` in the mapping as described on Ayende's blog.
Thanks for the suggestions but meanwhile I found an interesting solution, better I think.
Using the Visitor pattern, I can define an IconContent visitor and pass an Action to be executed to it.
For example, suppose there is a TextContent and an ImageContent, it will be something like this:
IconContentVisitor.Func(()=> { Console.WriteLine("this is TextContent"; }, ()=> { Console.WriteLine("this is ImageContent"));
Idea came from here: http://mookid.dk/oncode/archives/991