Create and download CSV in PHP
Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.
The other day, I faced the task of sorting the output of products according to a table that is not described in schema.xml. I will give a brief example of the table schema and table structure with positions, by which I should have sorted the products.
Simplified product table (merged the translation table with the main one and truncated the fields):
id | (int) | product id |
name | (string) | Name |
create_date | (int) | the date |
Schema of this table (schema.xml):
<table name="shop_products" phpName="SProducts">
<vendor type="mysql">
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" autoIncrement="true" primaryKey="true"/>
<column name="name" type="varchar" size="500" required="true"/>
<column name="create_date" type="INTEGER"/>
</table>
Let's say we have a binding of products to articles, and each article can have the same product and each product can have its own position in each article.
I will give an example of a table of articles and product links (let's call the table link_page):
page_id | (int) | Article ID (given as an example) |
product_id | (int) | Product ID from the SProducts schema |
position | (int) | The position in which the product is in the article |
Here there is a position for each product in the article, but there is no link in the product table to make join a sing-song. So let's start doing this:
SProductsQuery::create()
->addJoin('shop_products.id' , 'link_page.product_id', Criteria::INNER_JOIN)
->addAsColumn('position', 'link_page.position')
->where('page_link_product.page_id = ' . 'ID страницы товара')
->orderBy('position','ASC')
->find();
In my case, the full path to Criteria::INNER_JOIN is \Propel\Runtime\ActiveQuery\Criteria::INNER_JOIN .
SProductsQuery - the generated model according to the scheme, simplified for understanding and described above.
This query will make it possible to connect a table not declared in the models to the query, so as not to make crutches and bicycles for sorting.
Try it, figure it out, in my case, addJoin() allowed me to save the time of rewriting and regenerating the schema for the needs, thereby not burdening the page of the article, which contains products.
Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.
Latest templates from ImageCMS 4.12, authorization is required to download.
Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.
Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.
When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.
After developing any tool in PHP, the question becomes how resourceful the created code is and what elements it still affects. Let's take a look at xhprof installation, configuration, and how to work with xhprof.
Let's analyze the possibility of combining conditions in a query by groups in Propel. Consider an example of filtering by fields using ->condition() and ->combine().
Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .