How to call zendframeworklib in thinkphp

Source: Internet
Author: User
Copy all the file directories under zendframeLib to the org directory of thinkphp. (ThinkPHP \ Extend \ Library \ ORG \) this is the directory path of thinkphp3.0. Other versions may be different. Then write a script to change the file suffix from. php to. class. php.

To use the zendframe mail function in the thinkphp framework, record the operation procedure as follows:

Copy all the file directories under zendframe Lib to the org directory of thinkphp (ThinkPHP \ Extend \ Library \ ORG \). This is the directory path of thinkphp3.0. Other versions may be different. Then write a script to change the file suffix from. php to. class. php.

Then you can call thinkphp. add 'app _ AUTOLOAD_PATH '=> 'org' to the PHP file (custom search path ). However, this is not complete because the zend class name cannot be mapped to the corresponding file path in the autoload method of thinkphp, you have to modify the autoload method of thinkphp (use the underline in the class name to separate the assembly path ). At the same time, modify the import function (because the import function will automatically treat the string of the last segment as the class name)

Then, you can use the zend_mail class that I want to use. the code is given below.

Prompt: In the past, I thought that tp's autoload implementation was not good. First, it could not be extended, and it could not be searched for subdirectories.
  1. Autoload // shi_mody
  2. $ ClassPart = explode ('_', $ class );
  3. $ Class2 = implode ('.', $ classPart );
  4. // Shi_mody end
  5. Foreach ($ paths as $ path ){
  6. // Var_dump ($ path. '.'. $ class2 );
  7. If (import ($ path. '.'. $ class2) // shi_mody: $ class => $ class2
  8. // If the class is successfully loaded, return
  9. Return;
  10. }

Import function:

  1. If (strpos ($ class, 'org/zend') = 0 ){
  2. $ Classname = preg_replace ('//', '_', substr ($ class, 4 ));
  3. } Else {
  4. $ Classname = basename ($ class );
  5. }
  6. If (! Class_exists ($ classname, false )){
  7. // If the class does not exist, import the class library file
  8. Return require_cache ($ classfile );
  9. }

Script for file name change:

  1. $ Dir = "Validate /";
  2. TraceDir ($ dir, "reClass ");
  3. Function reClass ($ file ){
  4. If (strpos ($ file, "class. php ")){
  5. $ NFile = preg_replace ('/\. php/', "class. php", $ file); // Remember that the filename suffix meets the conditions
  6. Rename ($ file, $ nFile );
  7. }
  8. }
  9. Function traceDir ($ dir, $ callback ){
  10. $ H = opendir ($ dir );
  11. While ($ file = readdir ($ h ))){
  12. If ($ file = "." | $ file = "..")
  13. Continue;
  14. If (is_dir ($ dir. $ file )){
  15. TraceDir ($ dir. $ file. "/", $ callback );
  16. } Else {
  17. Call_user_func_array ($ callback, array ($ dir. $ file ));
  18. }
  19. }
  20. }

Call zend_mail:

  1. Class RssAction extends BaseAction {
  2. Public function send (){
  3. $ Email = addslashes ($ _ POST ['email ']);
  4. $ Title = addslashes ($ _ POST ['title']);
  5. $ Cont = $ _ POST ['cont'];
  6. // Import ("ORG. zend. mail "); // You do not need to import it here. In addition, the default zend class library in the tp framework is placed in ThinkPHP \ Extend \. if you use the default tp method, import is required in advance. at this time, if other class names are referenced in the class file, a large series of classes need to be imported.
  7. $ Smtp = new Zend_Mail ();
  8. $ Host = "smtp.qq.com ";
  9. $ Config = array (
  10. "Port" => 25,
  11. "Auth" => "Login ",
  12. "Username" => "werwer@qq.com ",
  13. "Password" => "werwer23"
  14. );
  15. Try {
  16. $ SmtpTrans = new Zend_Mail_Transport_Smtp ($ host, $ config );
  17. $ Mail = new Zend_Mail ();
  18. $ Mail-> setDefaultTransport ($ smtpTrans );
  19. $ Mail-> setBodyHtml ($ cont );
  20. $ Mail-> setFrom ($ config ["username"], "kindlerss.net ")
  21. -> AddTo ($ email, $ email)
  22. -> SetSubject ($ title );
  23. $ Mail-> send ();
  24. } Catch (Exception $ ex ){
  25. Echo $ ex-> message;
  26. }
  27. }
  28. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.