JCarousel widget on Yii framework don't load image - yii

I'm trying to use JCarousel widget on Yii framework.
My JCarousel must show images of specific user that belong to a specific gallery (for that user).
I retrieve the information about the images from a MySQL DB, in the specific from Photos table, where gallery_id have a determined value. The column from Photos table that contain the name of the photos is "path".
In the code I have written this:
$DataProvider = new CActiveDataProvider('Photos', array('criteria'=>array(
'condition'=>'gallery_id = :id',
'params'=>array(':id'=>$gallery->id),
),));
$this->widget('ext.JCarousel.JCarousel', array(
'dataProvider' => $DataProvider,
'thumbUrl' => '"/images/upload/".$data->id."_".$data->path',
'imageUrl' => '"/images/upload/".$data->id."_".$data->path',
'target' => 'big-gallery-item',
'vertical' => false,
));
With this code I get, on the div, the written message: "No result find"
Where I did i go wrong?

Check your dataProvider. Try get results via $DataProvider->getData() and check that you photos exists.
I do not think that the error in the extension, most likely you do not select data from the database.

Related

How to add a dynamic validation rule to a form field in dev express

Good day, I am new to Dev express and also to razor pages.
I have a dev extreme data grid with a list of users, a user has a user type the user type has a min range and a max range for the user id.
What I want is to set a range validation rule on a column on the standard edit form of the datagrid so when you add a new user id the user id should be between for example 1 and 49999. The range is stored in a database. So the user first selects the user type, the usertype table will have a range in it for example a user type of "Employee" will have a range of min 1 max 49999, this range I want to use as validation on my form.
My DevExtreme datagrid code currently :
#(Html.DevExtreme().DataGrid<ACS.LIB.BE.User>().ID("userGrid")
.ElementAttr(new { #class = "dx-card wide-card" })
.DataSource(d => d.Mvc().Controller("User")
.LoadAction("Get").Key("ID")
.InsertAction("InsertUser")
.UpdateAction("UpdateUser")
.DeleteAction("DeleteUser"))
.ShowBorders(false)
.FilterRow(f => f.Visible(true))
.FocusedRowEnabled(true)
.FocusedRowIndex(0)
.ColumnAutoWidth(true)
.ColumnHidingEnabled(true)
.Columns(columns =>
{
columns.AddFor(m => m.ID).ValidationRules(val => val.AddRange().Min(100));
columns.AddFor(m => m.Name);
columns.AddFor(m => m.UserType.ID).Lookup(lookup => lookup
.DataSource(ds => ds.WebApi().Controller("UserType").LoadAction("Get").Key("ID"))
.DisplayExpr("Name")
.ValueExpr("ID")
).Caption("User Type");
columns.AddFor(m => m.Department.ID).Lookup(lookup => lookup
.DataSource(ds => ds.WebApi().Controller("Department").LoadAction("Get").Key("ID"))
.ValueExpr("ID")
.DisplayExpr("Name")
).Caption("Department");
columns.AddFor(m => m.Company.ID).Lookup(lookup => lookup
.DataSource(ds => ds.WebApi().Controller("Company").LoadAction("Get").Key("ID"))
.ValueExpr("ID")
.DisplayExpr("Name")
).Caption("Company");
columns.AddFor(m => m.Authority);
columns.AddFor(m => m.Email).ValidationRules(v => v.AddEmail().Message("Please enter a valid email address. yourname#yourdomain.com"));
columns.AddFor(m => m.Active).FilterValue(true);
})
The line I have a problem with is columns.AddFor(m => m.ID).ValidationRules(val => val.AddRange().Min(100));
The Min(100) I want to set it dynamically from a data source not hardcoded like it is now, the user first selects the Usertype and then I want to use the UserType table to get the range what the id should be in. So I want to fetch the 100 from my user table but I am not sure what the syntax would be or how I should go about doing it.
My usertype table :
My insert screen default popup from the edit dialog of the data grid.
Any help or pointers would be appreciated.
It looks like you need to define a custom validation rule instead. You can get a user type value using the options.data parameter in the validationCallback function.
Note that the best ASP.NET Core practice is to use model properties' Data Annotation validation attributes. DevExtreme ASP.NET Core components support them.
You can find code snippets in the Implement a Custom Validation Rule topic.

Yii 1 Pagination takes every params user inserted

I have my pagination url set to
www...com/category/detail.html?page=2
For which my code is,
$dataProvider = new CActiveDataProvider('Page', array('criteria' => array('condition' => 'status=1', 'condition' => 'category_id=' . $categoryObject -> id, 'order' => 'postDate DESC'), 'pagination' => array('pageSize' => 4,'pageVar'=>'page'), ));
$dataProvider->getData();
var_dump $dataProvider->totalItemCount;
I am getting the exact data counts and my pagination url seems working. I have my URL rule configured as
'index'=>'site/index',
'contact'=>'site/contact',
'privacy'=>'site/privacy',
'sitemap.xml'=>'site/sitemap',
'<category:\w+>' => 'category/detail',
'<category>/page/<page:\d+>' => 'category/detail',
'<category>'=>'category/detail',
'<category:\w+>/<postTitle:.+>' => 'category/post',
'<category:\w.+>/<postTitle:.+>'=>'category/post',
my auto generated pagination URl are working fine but,
If I manually insert url something like
www......com/category/detail.html?Page_page&page=2
www......com/category/detail.html?Page_pizza&page=2
or any stupid things I can put they navigates to the page.
Now, here I want to remove these extra parameters or I want my pagination url to be strict to
www...com/category/detail.html?page=2
and if I put any additional params I want an error page.
I have been working in this for 2 weeks and tried every possible ways I could.
You should set the "params" property of the pagination to an empty array:
'pagination' => array('pageSize' => 4,'pageVar'=>'page', 'params' => array()),
This will avoid exclude any GET parameters from pagination links(if you need any included, add their name there).
To throw an error, you need to check for the parameters in your action.
// remove valid prameters from get array.
$arr = array_diff_key($_GET, array_flip(array('page', 'postTitle', 'category')));
// if still there are parameters left, throw an error.
if(count($arr) > 0) {
throw new CHttpException('invalid parameter');
}

I use limit in GridView but show all record

$Property = Property::find()->limit(1)->orderBy(['id' => SORT_DESC]);
I use this query with GridView but show all record
When I use this query
$Property = Property::find()->limit(1)->orderBy(['id' => SORT_DESC])->all();
show error
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
Read the documentatio here:
http://www.yiiframework.com/doc-2.0/guide-output-data-providers.html#active-data-provider
Any existing limit and offset clauses will be overwritten by the
pagination request from end users (through the pagination
configuration).
Maybe try something like this:
$dataProvider = new ActiveDataProvider([
'query' => $Property ,
'pagination'=>[
'limit'=>1
]
]);
Read also detailed about pagination:
http://www.yiiframework.com/doc-2.0/guide-output-pagination.html
And if you only want to display 1 row from a table, maybe you should check DetailView instead of GridView.

Creating Prestashop back-office module with settings page

I'm creating a back-office module for Prestashop and have figured out everything except the best way to display the admin page. Currently I'm using the renderView() method to display the content of view.tpl.
I would like to display a table with values and an option to add a new row. Should I just create it in the view.tpl or is there a better way? I've seen the renderForm() method but haven't figured out how it works yet.
The biggest question I have is, how do I submit content back to my controller into a specific method?
ModuleAdminController is meant for managing some kind of records, which are ObjectModels. Defauly page for this controller is a list, then you can edit each record individually or view it's full data (view).
If you want to have a settings page, the best way is to create a getContent() function for your module. Besides that HelperOptions is better than HelperForm for this module configuration page because it automatically laods values. Define the form in this function and above it add one if (Tools::isSubmit('submit'.$this->name)) - Submit button name, then save your values into configuration table. Configuration::set(...).
Of course it is possible to create some sort of settings page in AdminController, but its not meant for that. If you really want to: got to HookCore.php and find exec method. Then add error_log($hook_name) and you will all hooks that are executed when you open/save/close a page/form. Maybe you'll find your hook this way. Bettter way would be to inspect the parent class AdminControllerCore or even ControllerCore. They often have specific function ready to be overriden, where you should save your stuff. They are already a part of execution process, but empty.
Edit: You should take a look at other AdminController classes, they are wuite simple; You only need to define some properties in order for it to work:
public function __construct()
{
// Define associated model
$this->table = 'eqa_category';
$this->className = 'EQACategory';
// Add some record actions
$this->addRowAction('edit');
$this->addRowAction('delete');
// define list columns
$this->fields_list = array(
'id_eqa_category' => array(
'title' => $this->l('ID'),
'align' => 'center',
),
'title' => array(
'title' => $this->l('Title'),
),
);
// Define fields for edit form
$this->fields_form = array(
'input' => array(
array(
'name' => 'title',
'type' => 'text',
'label' => $this->l('Title'),
'desc' => $this->l('Category title.'),
'required' => true,
'lang' => true
),
'submit' => array(
'title' => $this->l('Save'),
)
);
// Call parent constructor
parent::__construct();
}
Other people like to move list and form definitions to actual functions which render them:
public function renderForm()
{
$this->fields_form = array(...);
return parent::renderForm();
}
You don't actually need to do anything else, the controller matches fields to your models, loads them, saves them etc.
Again, the best way to learn about these controller is to look at other AdminControllers.

how to edit pagination behaviour in yii

hello i am creating a search module which is taking data from apis..
Now i am getting all result in 1 api call and i am making it as a dataProvider.
this is the code..
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name',
),
),
'pagination' => array(
'pageSize' => 10,
),
));
this is working fine and giving pagination. What i want to do is to use limit and ofset of api.
for eg consider the yelp api
http://api.yelp.com/search?term="xxx"&location="xxx"&limit=10&ofset=0;
i want to get only 10 result initially and i need another api call to get next set when i click the pagination [2] or next >.
how can this be done ?
I also need a expert opinion. which one is better.? calling api at single time and fetch all detail once or getting few one by one ? the expected results will be around 200..
Yelp doesn't allow to "cache" its search results in any meaning http://www.yelp.com/developers/getting_started/api_terms (section 6). So I believe you need to do call each time pagination link is clicked.
For this purpose I would create some YelpDataProvider extended from CDataProvider and override required abstract methods.
Pagination:
Not sure I got what kind of problem you faced with, but if you implement your own data provider you will have access to CPagination class instance and its properties pageSize and offset.
pageSize is to be mapped to limit yelp request parameter, offset property - directly to offset request param.
I hope this will help.
http://www.yiiframework.com/doc/api/1.1/CPagination
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name'),
),
'pagination' => array(
'pageSize' => 10,
'offset' => 5
),
));