search
HomeBackend DevelopmentPHP Tutorial新型ORM queryphp框架简介和教程入门解决办法

新型ORM queryphp框架简介和教程入门
目前网上很多php框架
国内 thinkphp还是不错的 qeephp也不错,但是写程序时候要写太多代码
国外 我经常使用symfony,这个确实是一个非常好的框架,也很多自动化,优美的验证方式,自动form
比起我们国内那种别扭验证方式很有开放性。
但是感觉太自动了,有时候想手工弄下,还得自己去写一个插件
还有symfony第一次有点慢,不过插件多 doctrine实现了jquery操作方式

能坚持使用下来只有js框架jquery jquery也比较小,google也给CDN了,所以自己服务器流量也小了

于是过年后几天顺手开发了queryphp框架,一种类拟jquery操作方式来写php程序。
如:supply和books都是数据库表。
echo $supply->Books->classname;//自动取得Books中内容
  echo $supply->Books->Supply->title; //反过来取supply中的内容
  echo $supply->title;
  echo $books->classname;

还支持hasOne hasMany ManyhasMany方式关联

还有PATH_INFO也支持
testframework.php?controller=default&action=index
testframework.php/default/index
可以使用apache重写 去掉testframework.php文件

下面贴些教程

这个一个微型框架
可以实现MVC方式

支持path_info方式

控制动作在router目录下面
/default/index
调用router目录下面defaultRouter.class.php文件
取得类后调用index方式
J()是index方法跳转
R()是由控制
C()是生成类
M()是数据库类模型 数据库链接在model.function.php里面设置

只包括framework.php文件就可以了。

path_info方式
testframework.php?controller=default&action=index
testframework.php/default/index

可以使用apache重写 去掉testframework.php文件

可以自己设置路由规则
C("router")->ruleMaps("login",'/login/:id', array('controller' => 'auth', 'action' => 'login'));
那么会配匹testframework.php/login/5555
这样可以使用$_GET['id']得到5555;
'controller' => 'auth', 'action' => 'login'
是控制器和方法

其它设置
C("router")->ruleMaps('logout','/logout', array('controller' => 'auth', 'action' => 'logout'));
C("router")->ruleMaps('signup','/signup', array('controller' => 'auth', 'action' => 'signup'));
C("router")->ruleMaps('profile','/profile/:action', array('controller' => 'profile')); // will call controller "Profile" with dynamic method ":action()"
C("router")->ruleMaps('users','/users/:id', array('controller' => 'users'), array('id' => '[\d]{1,8}')); // define filters for the url parameters


数据库数据模型
使用方法

构造一个数据库表模型
$beian=M('beian');

自动填充aaa bbb字段 $_POST中也要有这两个字段
//$beian->autoField(array("aaa","bbbb"));
$data中填充
$beian->autoField($data,array("aaa","bbbb"));
取两个主键值,排序为升序
//print_r($beian->get(53,54,'asc'));

赋值给字段。
$beian->userid=2;
$beian->language=1;


打印已经赋值字段
//print_r($beian->data);

保存,再显示刚才插入的ID
//echo $beian->save()->pkid();

设置主键然后删除
//echo($beian->pkid(69)->delete());

取得表的行数
//echo $beian->Totalnum();

select显示两个字段,Arraylist为数组
//print_r($beian->getAll("userid,language")->record); //改为record了

查询两个userid和language为1和5,fetch为取值
print_r($beian->whereUseridAndLanguage('1','5')->fetch()->record);

取得两个主键,显示三个字段,升序
//print_r($beian->get('confid,userid,language',53,54,'asc')->record);

输出主键值
//echo $beian->confid;

更新某个表的字段累加1
$beian->colupdate('tplid');

可以在model目录下,*****Model.class.php文件里面添加方法。

生成模型后可以马上可以使用
print_r($booktype=M("booktype")->getAll());


更新J()跳函数
可以支持各个路由之间跳转和传递参数
参数为array
J("show") 为转到本路由方法show
J("show",array("id"=>555)) 为转到本路由方法show 并传递参数ID过去
J(R("member"),"list") 将跳转到member路由上面并调用list方法 如果没有list那么默认为index方法,具体框架中设置的默认方法。
J("member")
J("member","list",array("userid"=>999))


hasOne hasMany ManyhasMany ORM(Object-Relational Mapper) 对象关系影射有三种可以在"map"=>"hasOne"这里更改
模型文件自动生成

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php class supplyModel extends supplyBase{   var $mapper=array("Books"=>array("map"=>"hasOne","TargetModel"=>"booktype","localFiled"=>"typeid","targetFiled"=>"typeid"));  var $maps;}?><div class="clear">
                 
              
              
        
            </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)