Table initialization in Zend framework 2 - zend-framework2

i am new to the Zend Framework 2.Any body can tell me that where i can initialize the tb table in ZF2 model? For example i want to select all the records form the user table in FZ2 model.
Regards,
Tauqeer

$db = $this->db;
$select = $this->db->select(false)
->from('user');
Try this one
refer this url http://framework.zend.com/manual/1.12/en/zend.db.select.html

Related

Zend tableGateway Model Delete Query with Multiple IDs

I want to delete multiple rows by TableGateway like below SQL
Delete from table where id in (1,2,5,6) - CSV of multiple ids.
See documentation at https://docs.zendframework.com/zend-db/table-gateway/
Build a Where object to pass as parameter :
$where = new Where();
$where->in('id', [1,2,5,6]);

How to show form drop down from database in Zend Framework 2.4.0?

I want to show brands in dropdown. I have the brands in brand table. How to show it in from. I'm Zend beginner. (ZF2.4.0)
This blog post does a very good job explaining how to do what you need: http://samminds.com/2013/03/zendformelementselect-and-database-values/
Doctrine ORM provides a ready-made element EntitySelect for doing this, but that only helps if you're using Doctrine ORM. If you're using Doctrine DBAL or Zend\Db you'll need to do it yourself by first querying the database to load a list of your brands then passing that array into the Select form element's value_options key.

zend 2: edit data before validation

I'm using zend framework 2 and I need to edit the data from the form before validation.
With this function I will take the data from the post method, but do not know how to edit it because the object is a protected type
$request = $this->getRequest();
$data = $request->getPost();
and do what you want with it...
then you can do:
$form->setData($data);

Adding new data to DB when using 2 tables

I am new to mvc and mvc 3 , I have a db that contain a company table (string id =as the company name )
And a table tourism that contain same info I would like to be able to add data to the tourism table , while selecting a company from the list (that came from the company table)
(The two tables had a dependency vie company_id (and the same name in both))
How can I do it?
Leo_a
create a transaction
insert into the dependent table
inserrt into the main table
commit
I'm not sure I understand the question. You want to select from one table and update the other with the data you selected from the first? Do you have any sample code you can post?

ASP.NET MVC generic view for displaying data

I am working on a project involves exposing many data entities (more than 200) through an ASP.NET MVC application.
I do not want to write views for every entity mode and I am wondering if there is a way of having one generic view to display different models (for example, a view which reads the model properties(metadata) and generates a HTML table to display a list of entities.
If you only need to display, you can write your own generic renderer in few minutes using reflection. Or, you can use ModelVisualizer from MvcContrib, or Grid from MvcContrib which can do Html.Grid(Model).AutoGenerateColumns() to automatically show properties as columns. It doesn't support DataAnnotations or attributes, but you can write your own extension method that will use reflection to generate Grid's columns based on some attributes. And you can quickly turn this grid into jqGrid using jqGrid's tableToGrid() method.
If you need input support, there're several choices:
MvcContrib's InputBuilder (here you can see a simple example on how it's done with reflection)
MVC v2 InputFor(), I think it supports rendering several properties, but I'm not sure.
My solution does read metadata (attributes) from view models and generates jqGrid formatting and editing options automatically.
There should be commercial tools, too.
Two choices:
Dynamic Data Project
Have you tried Asp.net Dynamic data project that can automagically create what you need?
Asp.net MVC
But if you want to do what you're asking, you can always create a single view that will not have a strong type model. You will always pass data to it ViewData dictionary. The view would then parse that data and display what's required.
Routing
You can always create these two routes:
routes.MapRoute(
"EntityRoute",
"{entityName}",
new {
controller = "Entity",
action = "Display",
entityName = "SomeDefaultEntity" }
);
routes.MapRoute(
"EntityRoute",
"{entityName}/{recordId}",
new {
controller = "Entity",
action = "Details",
entityName = "SomeDefaultEntity",
recordId = string.Empty }
);
that will redirect all requests to the same controller action that will provide correct entity set data and pass it into the ViewData dictionary and return the view that will consume it. The second one will display details of a certain record within some entity (in case you need to provide master/details functionality).
MVC Contrib has Model Visualizer which let you display a Model by reflecting its properties. That a no go if you need any performance at all, but maybe it gets you started.

Resources